import { createStore } from "vuex";
import { ethers } from "ethers";
import createPersistedstate from 'vuex-persistedstate'
import {  usdtContract,btcContract,isShowError } from "../utils/config";
export default createStore({
  state: {
    produceBB:0,
    cumulativeBtcb :0,
    tokenPrice:0,
    isShowError:isShowError,
    isShowBtn:false,
    hasPriority:false,
    isBroker:false,
    userInfo:{},
    myParent:'',
    themeColor:'#fd8800',
    address0:'0x0000000000000000000000000000000000000000',
    address: "",
    balance: "",
    usdtBalance:"0",
    btcBalance:"0",
    theme: "light",
    tokenName: "USDT",
    USDT:usdtContract[1],
    usdtImg:usdtContract[4], 
    BTC:btcContract[1],
    btcImg:btcContract[4],
  },
  getters: {},
  mutations: {
    changeProduceBB(state,payload ){
      state.produceBB = payload;
    },
    changeCumulativeBtcb(state,payload ){
      state.cumulativeBtcb = payload;
    },
    changeTokenPrice(state,payload ){
      state.tokenPrice = payload;
    },
    changeMyParent(state,payload ){
      state.myParent = payload;
    },
    changeUsdtBalance(state, payload) {
      state.usdtBalance = payload;
    },
    changeUserInfo(state,payload ){
      state.userInfo = payload;
    },
    changeBtcBalance(state, payload) {
      state.btcBalance = payload;
    },
    addTheme(state, payload) {
      state.theme = payload;
    },
    changeAddress(state, payload) {
      state.address = payload;
    },
    BALANCE(state, payload) {
      state.balance = payload;
    },
  },
  actions: {},
  plugins: [
    // 持久化插件
    createPersistedstate({
      storage: window.localStorage,
      reducer(val) {
        return {
          address: val.address,
          userInfo: val.userInfo
        };
      },
    }),


  ],
  modules: {},
});